

module.exports = {
    //判断设备状态是否正常
    fnGetStatus(status, option){
        let flag = true
        for(let prop in option){
            if(status[prop] !== option[prop]){
                flag = false
            }
        }
        return flag
    },
    fnGetDeviceStatusObj(status){
        let obj = {
            freezerStatus: false,
            thermotank1Status: false,
            thermotank2Status: false,
            inport1Status: false,
            inport2Status: false,
            outport1Status: false,
            outport2Status: false,
        }
        if(status.freezerControlMode === 1 && status.freezerWorkStatus === 1 && status.freezerDeviceStatus === 1){
            obj.freezerStatus = true
        }

        if(status.thermotank1ControlMode === 1 && status.thermotank1WorkStatus === 1 && status.thermotank1DeviceStatus === 1){
            obj.thermotank1Status = true
        }

        if(status.thermotank2ControlMode === 1 && status.thermotank2WorkStatus === 1 && status.thermotank2DeviceStatus === 1){
            obj.thermotank2Status = true
        }

        if(status.inport1Status === 1){
            obj.inport1Status = true
        }

        if(status.inport2Status === 1){
            obj.inport2Status = true
        }

        if(status.outport1Status === 1){
            obj.outport1Status = true
        }

        if(status.outport2Status === 1){
            obj.outport2Status = true
        }

        return obj
    },
    fnGetNewDevicesStatus(arr) {
        return {
            freezerControlMode: arr[4],
            freezerWorkStatus: arr[5],
            freezerDeviceStatus: arr[6],
            thermotank1ControlMode: arr[7],
            thermotank1WorkStatus: arr[8],
            thermotank1DeviceStatus: arr[9],
            thermotank2ControlMode: arr[10],
            thermotank2WorkStatus: arr[11],
            thermotank2DeviceStatus: arr[12],
            outport1Status: arr[13],
            outport2Status: arr[14],
            inport1Status: arr[15],
            inport1MealId: arr[16],
            inport2Status: arr[17],
            inport2MealId: arr[18],
            warning1: arr[19],
            warning2: arr[20],
            status: 1
        }
    },
    fnCheckData(arr) {
        //头信息错误
        if (arr[0] !== 170) {
            return {
                code: 1,
                msg: '头信息错误'
            }
        }
        //数据长度错误
        if (arr[3] / 2 + 4 !== arr.length) {
            return {
                code: 2,
                msg: '数据长度错误'
            }
        }
        return {
            code: 0,
            msg: 'ok'
        }
    },
    fnGetFurnaceStatus(num1, num2){
        let str1 = num1.toString(2)
        let str2 = num2.toString(2)
        let length1 = str1.length
        if(length1 < 16){
            for(let i = 0; i < 16 - length1; i ++){
                str1 = '0' + str1
            }
        }
        if(str2.length < 2) str2 = '0' + str2
        let str = str2 + str1 
        let arr =str.split('').reverse()
        return arr.map(item => item === '1')
    }
}